Skip to content

Polyhedron potential field kernels - #89

Draft
jcapriot wants to merge 3 commits into
simpeg:mainfrom
jcapriot:jcapriot/polyhedron-kernels
Draft

jcapriot wants to merge 3 commits into
simpeg:mainfrom
jcapriot:jcapriot/polyhedron-kernels

Conversation

@jcapriot

@jcapriot jcapriot commented Oct 7, 2026

Copy link
Copy Markdown
Member

This draft is the start of adding polyhedron kernels for the potential fields methods.

For now they are checked for consistency against the prism formulations, and that they match their behavior at degenerate points.
The consistent degenerate behavior is specifically because I wanted them to cancel out if necessary. Say someone wanted to compute the magnetic field of a prism minus a polygon, in such a way the the point is outside the linearly combined body, but is evaluated at a degenerate point (say the top face).

@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.24896% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.79%. Comparing base (7c47ec2) to head (0d9761a).

Files with missing lines Patch % Lines
geoana/shapes.py 87.89% 15 Missing and 12 partials ⚠️
geoana/kernels/potential_field_polyhedron.py 92.53% 7 Missing and 3 partials ⚠️
geoana/em/static/freespace.py 82.60% 5 Missing and 3 partials ⚠️
geoana/kernels/_extensions/__init__.py 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
+ Coverage   83.87%   84.79%   +0.92%     
==========================================
  Files          31       32       +1     
  Lines        3169     3631     +462     
  Branches      268      312      +44     
==========================================
+ Hits         2658     3079     +421     
- Misses        443      465      +22     
- Partials       68       87      +19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jcapriot and others added 2 commits October 20, 2026 15:54
Closed-form gravity and magnetic solutions for closed triangulated
polyhedra and tetrahedra (Werner and Scheeres, 1996), with Polyhedron,
Tetrahedron, MagneticPolyhedron and MagneticTetrahedron classes, and a
broadcasting tetrahedron_integrals / tetrahedron_inside_fraction path for
evaluating many tetrahedra at once.

The potential and field are continuous across every face, edge and
vertex. Edge line integrals and face solid angles are evaluated without
cancellation, coplanar faces are merged into polygons so triangulation
diagonals play no part, and shared faces cancel exactly between bodies.
On the surface, the gradient tensor follows Prism's conventions, so
tetrahedra tiling a prism sum to it there as well.

Prism: evaluate the log kernels without cancellation near edges, and
weight the magnetization in B by the fraction of a small sphere inside
the prism, making B's normal component exact on its faces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jcapriot
jcapriot force-pushed the jcapriot/polyhedron-kernels branch from 0dae788 to 4bfaeb6 Compare October 20, 2026 21:54
Fixes from reviewing simpeg#89:
- split the surface into closed shells and wind each one by how deeply it's nested (outer shells outward, cavities inward). Before, a mixed winding surface was flipped all at once based on the total volume, so an inward shell counted as negative density.
- allow edges shared by more than two faces (shells touching along an edge) by pairing forward and backward faces within each shell. The edge dyad is a sum over faces so the pairing doesn't change anything.
- sum the edge and face terms into the output in blocks, so memory scales with the output instead of points x edges (chunking the points is left to the caller).
- get the inside fraction from the same pass as the hessian in `magnetic_flux_density`
- keep the single log in `prism_fzx` and `prism_fzy`, but fall back to `log(r - y) - 2 log(hypot(x, z))` when `x**2 + z**2` is subnormal or the ratio would overflow (it gave inf or a wrong value there)
- clearer errors for fewer than 4 faces and for faces that repeat a vertex

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant